<?php


namespace app\api\controller\v31;


use app\aliyun\controller\AliyunFilterWord;
use app\api\controller\v2\Auth;
use app\common\cachemodel\AppConfig;
use app\common\cachemodel\ArticleComment;
use app\common\cachemodel\ArticleCommentReply;
use app\common\cachemodel\Goods;
use app\common\cachemodel\ZhunleActivity;
use app\common\cachemodel\zlcr2\Zlcr2QuestionUserView;
use app\common\cachemodel\zlcr2\Zlcr2UserAddQuestion;
use app\common\cachemodel\zlcr2\Zlcr2UserQuestion;
use app\common\cachemodel\zlcr2\Zlcr2UserQuestionComment;
use app\common\cachemodel\zlcr2\Zlcr2UserSameQuestion;
use app\common\cachemodel\ZlcrAppeal;
use app\common\cachemodel\ZlcrAstr;
use app\common\cachemodel\ZlcrAstrMessage;
use app\common\cachemodel\ZlcrTag;
use app\common\cachemodel\ZlUserVip;
use app\common\lib\SensorsData;
use app\common\lib\tarot\Tarot;
use app\common\lib\Util;
use app\common\model\Recode;
use app\common\model\User;
use app\common\model\UserPush;
use think\Cache;
use think\Env;
use think\Log;
use think\response\Json;
use XznsTools\cache\CacheManage;

class UserQuestionAnswer extends Auth
{
    /**
     * 获取提问信息 提问介绍信息
     */
    public function getAskQuestionIntro()
    {
        $qid = input('qid/s', '');
        $qtype = input('qtype/d', 0);
        $channel = $this->request->header('channel');
        $is_huawei = 0;
        if ($channel === 'huawei')
        {
            $is_huawei = 1;
        }

        $question = '';
        if ($qid)
        {
            if ($qtype === 1)
            {
                $questionInfo = (new Zlcr2UserQuestion())->getInfoById($qid, ['question']);
            } else
            {
                $questionInfo = (new \app\common\cachemodel\zlcr2\GuessQuestion())->getInfoById($qid, ['question']);
            }

            $question = $questionInfo['question'] ?? '';
        }

        $goodInfo = (new Goods())->GoodsTypeInfo(22);
        (new ZhunleActivity())->goodsActiveInfo(22, $goodInfo);

        $goodList = [];
        $goodTypeConfig = [
            1 => 'astro',
            2 => 'dice',
            3 => 'tarot',
        ];
        foreach ($goodInfo as $goodItem)
        {
            if (($goodItem['is_add'] === 0) && isset($goodTypeConfig[$goodItem['type']]))
            {
                $activePrice = isset($goodItem['active']) ? $goodItem['active']['price'] : 0;
                $goodList[$goodTypeConfig[$goodItem['type']] . '_price'][] = [
                    'gid' => $goodItem['id'],
                    'type' => 1,
                    'price' => (string)((float)$goodItem['now_prize']),
                    'active_price' => $activePrice,
                    'level_img' => $goodItem['img'],
                    'des' => $goodItem['des'],
                    'selected_des' => $goodItem['select_des'],
                    'img' => '',
                ];
            }
        }
        // 补充一个"暂未开通，敬请等待"的商品
        foreach ($goodList as $key => $item)
        {
            $goodList[$key][] = [
                'gid' => 0,
                'type' => 0,
                'price' => 0,
                'level_img' => '',
                'des' => '',
                'selected_des' => '',
                'img' => '/test/question_answer/good_intro.png',
            ];
        }
        $data = [
            'is_limit' => 0,
            'question_title' => $question,
            'price_list' => $goodList,
            'question_title_tips' => '骰子、' . ($is_huawei ? '卡牌' : '塔罗') . '只能问三个月内的事，一次仅限一个问题', // 例如：我今年适合创业吗？我未来两个月会脱单吗？
            'question_title_tips2' => '例如：双子座是不是都是渣男？', // 例如：双子座是不是都是渣男？大家觉得我和摩羯座合拍吗？
            'tips' => [
                'title' => '免费提问怎么问？',
                'des' => "1.针对星座提问，让更多人讨论、解答\r\n2.把问题描述清楚，便于用户理解\r\n3.避免问大家不能解决的问题，如看盘等",
            ],
            'guide_url' => Env::get('host.domain') . '/web/agreement/guide?is_huawei=' . $is_huawei,  // 引导问题H5页面地址
            // v2.8.3新增弹窗提示信息
            'notice_info' => [
                'astro' => null,
                'dice' => [
                    'title' => '特别提示',
                    'des' => "一次悬赏仅限一个问题\r\n骰子提问只针对于“三个月以内具体的事情”。\r\n例如：这次考试会顺利吗？\r\n这个月我可以还清债务吗？\r\n这周内我会脱单吗？",
                ],
                'tarot' => [
                    'title' => '特别提示',
                    'des' => "一次悬赏仅限一个问题\r\n" . ($is_huawei ? "卡牌" : "塔罗") . "提问只针对于“半年内具体事件的发展情况”。\r\n例如：近三个月内我跟他的关系发展如何？\r\n半年内我们能复合吗？",
                ],
                'publish' => [
                    'title' => '悬赏须知',
                    'des' => "一、一次悬赏仅限一个问题，如包含多个问题，咨询师有权只回答1个问题；平台不予退款。\r\n二、骰子提问只针对于“三个月以内具体的事情”。\r\n三、" . ($is_huawei ? "卡牌" : "塔罗") . "提问只针对于“半年内具体事件的发展情况”。\r\n四、星盘提问针对于“长期运势、人生大事件”。",
                    'attention' => '为了你的问答准确度，请务必阅读以上信息',
                ],
            ],
        ];

        return show(config('code.success'), '请求成功', $data);
    }

    /**
     * 发布问题
     */
    public function questionAdd()
    {
        $qid = input('qid/d', 0);
        $qtype = input('qtype/d', 0);   // 1=>别人的提问 2=>猜你想问
        $questionType = input('question_type/d', 0); // 0=>免费问题 , 1=>星盘问题,2=>骰子问题,3=>塔罗问题 （1、2、3属于悬赏问题）
        $photoListStr = input('photo_list/s', '');
        $question = input('question/s', '');
        $questionDes = input('question_des/s', '');
        $astroData = input('astro_data/s', '');
        $diceData = input('dice_data/s', '');
        $tarotData = input('tarot_data/s', '');
        $gid = input('gid/d', 0);
        $isAnonymity = input('is_anonymity/d', 0);  // 是否匿名
        $isHide = input('is_hide/d', 0);
        if (!$question)
        {
            return show(config('code.error'), '请输入咨询问题');
        }

        if ($questionType === 0 && (mb_strlen($question) < 6 || mb_strlen($questionDes) < 12))
        {
            return show(201, "你发布的内容过短，问题至少6个字，描述至少12个字。\r\n为了让更多人对你的问题发表看法，请尽量发布关于星座的问题，方便大家理解。");
        }

        if (mb_strlen($question) > 30)
        {
            return show(config('code.error'), '咨询问题最多30字');
        }

        if (mb_strlen($questionDes) > 100)
        {
            return show(config('code.error'), '咨询问题描述最多100字');
        }

        if (!in_array($questionType, [0, 1, 2, 3,], true))
        {
            return show(config('code.error'), '请求异常，请稍后再试～');
        }

        if ($photoListStr)
        {
            $photoList = json_decode($photoListStr, true);
            if ($photoList === null || count($photoList) > 3)
            {
                return show(config('code.error'), '请求异常，请稍后再试～');
            }
            //对图片进行校验
            $ossHost = Env::get('host.photo');
            foreach ($photoList as $photo)
            {
                $res = AliyunFilterWord::checkImg(1, $ossHost . $photo, 'question_pic_check');

                if ($res['status'] === false)
                {
                    return show(config('code.error'), '图片包含' . $res['text']);
                }
            }
        }
        if (!in_array($isAnonymity, [0, 1], true))
        {
            return show(config('code.error'), '请求异常，请稍后再试～');
        }

        if ($questionType === 0 && $this->user['no_comment'])
        {
            return show(201, '发布问题失败，已被禁止发布问题');
        }

        if (Util::commentCheck($this->user['id'], [
            'question_type' => $questionType,
            'question' => $question,
            'question_des' => $questionDes,
            'astro_data' => $astroData,
            'dice_data' => $diceData,
            'tarot_data' => $tarotData,
            'photo_list' => $photoListStr,
            'gid' => $gid,
            'is_anonymity' => $isAnonymity,
            'is_hide' => $isHide,
        ]))
        {
            return show(config('code.error'), '请求频繁，请稍后再试～');
        }

        $res = AliyunFilterWord::checkText($question, 'question_pic_check');
        //若内容有违规且超过配置的相似比例，则进行隐藏不显示，将标签存入库中
        if ($res)
        {
//            return [
//                'status' => false,
//                'msg' => '问题中有敏感词'
//            ];
            return show(config('code.toast'), '问题中有敏感词');
        }
        $res = AliyunFilterWord::checkText($questionDes, 'question_des_check');
        //若内容有违规且超过配置的相似比例，则进行隐藏不显示，将标签存入库中
        if ($res)
        {
//            return [
//                'status' => false,
//                'msg' => '问题描述中有敏感词'
//            ];
            return show(config('code.toast'), '问题描述中有敏感词');
        }

        $questionData = [
            'id' => Util::createQuestionAnswerId(),
            'uid' => $this->user['id'],
            'status' => $questionType > 0 ? 0 : 6,
            'question_type' => $questionType,
            'question' => $question,
            'question_des' => $questionDes,
            'question_imgs' => $photoListStr,
            'gid' => $questionType > 0 ? $gid : 0,
            'is_anonymity' => $isAnonymity,
            'is_read' => 1,
            'create_time' => $this->request->time(),
        ];
        // 记录 占星师下单时的版本号
        $questionExtend = ['version' => $this->headers['version']];
        if ($questionType)
        {
            //獲取當前商品所屬問題類型
            $questionTypeInfo = (new Zlcr2UserQuestion())->getQuestionType($gid);
            if (isset($questionTypeInfo['sec']) && $questionTypeInfo['sec'] !== $questionType)
            {
                return show(config('code.error'), '服务异常');
            }

            $isSynastry = 0; // 是否合盘
            switch ($questionType)
            {
                case 1: // 看盘
                    $astroData = json_decode($astroData, true);
                    if (!$astroData || !isset($astroData['rid1'], $astroData['astro_type']) || !$astroData['rid1'] || !in_array($astroData['astro_type'], [1, 2], false))
                    {
                        return show(config('code.error'), '请求异常，请稍后再试～');
                    }

                    $recodeInfo1 = (new Recode())->getRecode(['id' => $astroData['rid1']]);
                    if (!$recodeInfo1 || $recodeInfo1['uid'] != $this->user['id'])
                    {
                        return show(config('code.error'), '请求异常！档案信息不存在～');
                    }
                    $questionExtend['recode1'] = [
                        'id' => (int)$astroData['rid1'],
                        'avatar' => $recodeInfo1['avatar'],
                        "name" => $recodeInfo1['name'],
                        "type" => (int)$recodeInfo1['type'],
                        "year" => (int)$recodeInfo1['year'],
                        "month" => (int)$recodeInfo1['month'],
                        "day" => (int)$recodeInfo1['day'],
                        "hour" => (int)$recodeInfo1['hour'],
                        "minute" => (int)$recodeInfo1['minute'],
                        "timezone" => (int)$recodeInfo1['timezone'],
                        "long_deg" => (int)$recodeInfo1['long_deg'],
                        "long_min" => (int)$recodeInfo1['long_min'],
                        "ew" => (int)$recodeInfo1['ew'],
                        "lat_deg" => (int)$recodeInfo1['lat_deg'],
                        "lat_min" => (int)$recodeInfo1['lat_min'],
                        "ns" => (int)$recodeInfo1['ns'],
                        "is_summer" => (int)$recodeInfo1['is_summer'],
                        "birth_country" => $recodeInfo1['birth_country'],
                        "birth_province" => $recodeInfo1['birth_province'],
                        "birth_city" => $recodeInfo1['birth_city'],
                        "live_country" => $recodeInfo1['live_country'],
                        "live_province" => $recodeInfo1['live_province'],
                        "live_city" => $recodeInfo1['live_city'],
                        "isself" => (int)$recodeInfo1['isself'],
                    ];

                    if ($astroData['astro_type'] == 2)
                    {
                        $recodeInfo2 = (new Recode())->getRecode(['id' => $astroData['rid2']]);
                        if (!$recodeInfo2 || $recodeInfo2['uid'] != $this->user['id'])
                        {
                            return show(config('code.error'), '请求异常！档案信息不存在～');
                        }
                        $questionExtend['recode2'] = [
                            'id' => (int)$astroData['rid2'],
                            'avatar' => $recodeInfo2['avatar'],
                            "name" => $recodeInfo2['name'],
                            "type" => (int)$recodeInfo2['type'],
                            "year" => (int)$recodeInfo2['year'],
                            "month" => (int)$recodeInfo2['month'],
                            "day" => (int)$recodeInfo2['day'],
                            "hour" => (int)$recodeInfo2['hour'],
                            "minute" => (int)$recodeInfo2['minute'],
                            "timezone" => (int)$recodeInfo2['timezone'],
                            "long_deg" => (int)$recodeInfo2['long_deg'],
                            "long_min" => (int)$recodeInfo2['long_min'],
                            "ew" => (int)$recodeInfo2['ew'],
                            "lat_deg" => (int)$recodeInfo2['lat_deg'],
                            "lat_min" => (int)$recodeInfo2['lat_min'],
                            "ns" => (int)$recodeInfo2['ns'],
                            "is_summer" => (int)$recodeInfo2['is_summer'],
                            "birth_country" => $recodeInfo2['birth_country'],
                            "birth_province" => $recodeInfo2['birth_province'],
                            "birth_city" => $recodeInfo2['birth_city'],
                            "live_country" => $recodeInfo2['live_country'],
                            "live_province" => $recodeInfo2['live_province'],
                            "live_city" => $recodeInfo2['live_city'],
                            "isself" => (int)$recodeInfo2['isself'],
                        ];
                        $isSynastry = 1;
                    }
                    break;
                case 2: // 骰子
                    $diceData = $diceData ? json_decode($diceData, true) : [];
                    if (!$diceData || !isset($diceData['planet'], $diceData['sign'], $diceData['house']))
                    {
                        return show(config('code.error'), '咨询骰子数据异常！');
                    }
                    $questionExtend['dice_data'] = $diceData;
                    break;
                case 3: // 塔罗
                    $tarotData = $tarotData ? json_decode($tarotData, true) : [];
                    if (!$tarotData || count($tarotData) !== 3)
                    {
                        return show(config('code.error'), '咨询塔罗数据异常！');
                    }
                    foreach ($tarotData as $item)
                    {
                        if (!isset($item['img'], $item['tips'], $item['name']))
                        {
                            return show(config('code.error'), '咨询塔罗数据异常！');
                        }
                    }
                    $questionExtend['tarot_data'] = $tarotData;
                    break;
                default:
            }

            $questionData['status'] = 0;    // 待下单
            $questionData['is_synastry'] = $isSynastry; // 是否合盘
            $questionData['is_hide'] = $this->user['no_comment'] ? 1 : 0;
        } else
        {
            $questionData['status'] = 6;    // 已完成
            $questionData['is_hide'] = 0;
            $questionData['consult_time'] = $this->request->time(); //咨询时间
        }
        $questionData['question_extend'] = json_encode($questionExtend, JSON_UNESCAPED_UNICODE);
        if ($isHide === 1)
        {
            $questionData['is_hide'] = 1;
        }
        try
        {
            $questionModel = new Zlcr2UserQuestion();
            $res = $questionModel->SaveData($this->user['id'], $questionData);
            if (!$res)
            {
                return show(config('code.error'), '服务异常，请稍后再试～');
            }
            $gid = $questionType > 0 ? $gid : 0;
            $questionGoods = Util::getZhunleQuestionAnswerConfig();
            $price = $questionGoods[$gid]['price'] ?? 0;
            $active = (new ZhunleActivity())->getActivingGood(22, $gid);
            //  问题提交成功    QuestionAddSuccess    打点
            SensorsData::track($this->user['id'], true, 'QuestionAddSuccess', [
                'is_anonymous' => $isAnonymity ? true : false,    // 是否匿名
                'is_added_photo' => $photoListStr ? true : false,    // 是否添加了图片
                'question_title' => $question,
                'question_type' => $questionType,
                'price' => $price,   // 套餐价格
                'is_official_active' => $active ? true : false,   // 是否有官方活动
                'active_name' => $active['name'] ?? '',    //活动名称
                'question_des' => $questionDes, // 问题的描述
            ]);
            if ($qid)
            {   // 同问 数增加
                if ($qtype === 1)
                {
                    $questionInfo = $questionModel->getInfoById($qid, ['read_num', 'comment_num', 'same_num', 'id', 'consult_time', 'status', 'is_hide']);
                    $questionModel->UpdateData($qid, ['same_num' => $questionInfo['same_num'] + 1]);
                    // 更新 推荐值
                    $questionModel->changeQuestionInfo($questionInfo, 3, 1);
                } else
                {
                    $guessQuestionModel = new \app\common\cachemodel\zlcr2\GuessQuestion();
                    $questionInfo = $guessQuestionModel->getInfoById($qid, ['same_num']);
                    $guessQuestionModel->UpdateData($qid, ['same_num' => $questionInfo['same_num'] + 1]);
                }

                (new Zlcr2UserSameQuestion())->SaveData([
                    'uid' => $this->user['id'],
                    'type' => $qtype === 1 ? 1 : 2,
                    'same_qid' => $qid,
                    'qid' => $questionData['id'],
                    'create_time' => $this->request->time(),
                ]);
            }

            return show(config('code.success'), '发布成功', ['qid' => $questionData['id']]);
        }
        catch (\Exception $e)
        {
            Log::write('问答 UserQuestionAnswer => questionAdd()异常：' . $e->getMessage() . '失败行数：' . $e->getLine(), 'error');
            return show(config('code.error'), '服务异常，请稍后再试～');
        }
    }

    /**
     * 获取塔罗或骰子结果
     * @throws \Exception
     */
    public function getTarotOrDice()
    {
        $type = input('type/d', 0); //2=>骰子, 3=>塔罗

        if (!in_array($type, [2, 3], true))
        {
            return show(config('code.error'), '请求异常，请稍后再试～');
        }
        $data = [];
        if ($type === 3)
        {   // 塔罗
            // 获取塔罗占卜结果
            $tarotData = (new Tarot())->getTarot(1);
            $tarotConfig = config('tarot');
            foreach ($tarotData as $tarotItem)
            {
                $data['tarot_data'][] = [
                    'img' => "/test/tarot/cards/{$tarotItem['card_id']}-{$tarotItem['direction']}.png",
                    'tips' => $tarotConfig['tarot_type'][$tarotItem['type']][$tarotItem['location']]['tip'],
                    'name' => $tarotConfig['card_list'][$tarotItem['card_id']]['name'] . '.' . ((int)$tarotItem['direction'] === 1 ? '正位' : '逆位'),
                ];
            }
        } else
        {   // 骰子
            $_arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 12, 16];// 行星id随机数种子
            $data['dice_data'] = [
                'planet' => $_arr[random_int(0, count($_arr) - 1)],
                'sign' => random_int(1, 12),
                'house' => random_int(1, 12),
            ];
        }

        return show(config('code.success'), '请求成功', $data);
    }

    /**
     * 获取申述标签
     */
    public function getAppealTag()
    {
        $tagModel = new ZlcrTag();
        $tag = $tagModel->getLevelTag(5, 0);
        $resDatra = [];
        foreach ($tag as $tagItem)
        {
            $resDatra[] = [
                'id' => (int)$tagItem['id'],
                'name' => $tagItem['tag_name'],
            ];
        }

        return show(config('code.success'), '请求成功', $resDatra);
    }

    /**
     * 问题答案申述
     * @return Json
     * @throws \Exception
     */
    public function questionAppeal()
    {
        $qid = input('qid/s', '');
        $reason = trim(input('reason/s', ''));
        $tid = input('id/d', 0);
        $tel = input('tel/s', '');

        if (Util::commentCheck($this->user['id'], ['qid' => $qid, 'action' => '用户申诉'], 10))
        {
            return show(config('code.error'), '请求频繁，请稍后再试～');
        }

        $questionModel = new Zlcr2UserQuestion();
        $questionInfo = $questionModel->getInfoById($qid, ['uid', 'status', 'complain_status']);

        if (!$questionInfo && $questionInfo['uid'] !== $this->user['id'])
        {
            return show(config('code.error'), '服务异常，问题不存在～');
        }

        if (!in_array($questionInfo['status'], [5, 6, 8], true))
        {
            return show(config('code.error'), '问题状态异常，申述失败');
        }

        if (in_array($questionInfo['complain_status'], [1, 2], true))
        {
            return show(config('code.error'), '已经申述过了，不能重复申述');
        }

        if (empty($reason))
        {
            return show(config('code.error'), '请输入申述原因描述');
        }

        if (mb_strlen($reason) > 120)
        {
            return show(config('code.error'), '申述原因描述最多120字');
        }

        if (empty($tel))
        {
            return show(config('code.error'), '请输入联系方式');
        }

        if (!$tid)
        {
            return show(config('code.error'), '请选择原因');
        }

        try
        {
            $appConfig = (new AppConfig())->configInfo('astro_fortune_change');
            if (isset($appConfig['appeal_switch']) && $appConfig['appeal_switch'] == 1 && Util::CheckAppVersion('2.9.4') === '小')
            {
                return show(202, '当前版本较低，为了您的申诉体验，请更新至最新版本。');
            }

            $tagInfo = (new ZlcrTag())->getInfoById($tid, ['tag_name']);
            if (!$tagInfo)
            {
                return show(config('code.error'), '请求异常，请稍后再试～');
            }
            $data = [
                'type' => 3,    // 1=>问题申诉，2=>评论申诉 3=>问答回复申述，4=>追问问题申述
                'reason' => $tagInfo['tag_name'] . ':' . $reason,
                'qid' => $qid,
                'contact' => $tel,
                'create_time' => $this->request->time(),
            ];
            (new ZlcrAppeal())->save($data);
            // 已申述
            $questionModel->UpdateData($qid, ['complain_status' => 1]);
            //  提交申述    QuestionComplainADD    打点
            SensorsData::track($this->user['id'], true, 'QuestionComplainADD', [
                'question_id' => $qid,
                'complain_reason' => $reason,
                'complain_content' => $tagInfo['tag_name'],
                'add_question_nums' => (new Zlcr2UserAddQuestion())->getQuestionAddQuestionNum($qid),
            ]);
            return show(config('code.success'), '申述成功');
        }
        catch (\Exception $e)
        {
            Log::write("问答-答案申述失败：{$e->getMessage()},Line:{$e->getLine()},File:{$e->getFile()}", 'error');
            return show(config('code.success'), '服务异常，申述失败～');
        }
    }

    /**
     * 获取评价标签
     * @return Json
     * @throws \Exception
     */
    public function getCommentTag()
    {
        $tagModel = new ZlcrTag();
        $tag = $tagModel->getLevelTag(4, 0);
        $tag = $tagModel->getQuestionAllsResrt($tag);

        return show(config('code.success'), '请求成功', $tag);
    }

    /**
     * 对答案进行评价
     * @throws \Exception
     */
    public function answerComment()
    {
        $qid = input('qid/s', '');
        $remark = trim(input('remark/s', ''));
        $tid = input('tid/d', 0);

        if (!$qid || !$tid)
        {
            return show(config('code.error'), '请求异常，请稍后再试～');
        }
        $questionModel = new Zlcr2UserQuestion();

        $questionInfo = $questionModel->getInfoById($qid, ['uid', 'status', 'gid', 'is_comment', 'astr_id', 'question_type']);

        if (!$questionInfo || $questionInfo['uid'] !== $this->user['id'])
        {
            return show(config('code.error'), '服务异常，问题不存在～');
        }

        if ($questionInfo['gid'] === 0)
        {
            return show(config('code.error'), '服务异常，免费问题不能评价～');
        }

        $tagInfo = (new ZlcrTag())->getInfoById($tid);

        if (!$tagInfo)
        {
            return show(config('code.error'), '请求异常，请稍后再试～');
        }

        if ($tagInfo['flag'] < 3 && empty($remark))
        {
            return show(config('code.error'), '理由不能为空');
        }

        if (mb_strlen($remark) > 60)
        {
            return show(config('code.error'), '理由最多60字');
        }
        if (!in_array($questionInfo['status'], [5, 6, 8], true))
        {
            return show(config('code.error'), '问题状态异常，评价失败');
        }

        // 写入评价数据
        (new Zlcr2UserQuestionComment())->save([
            'qid' => $qid,
            'level' => $tagInfo['flag'],
            'tid' => $tid,
            'comment' => $remark,
            'astr_id' => $questionInfo['astr_id'],
            'comment_type' => 1,
            'create_time' => $this->request->time(),
        ]);
        // 更新评价状态
        $questionModel->UpdateData($qid, [
            'is_comment' => 1,
        ]);

        if ($questionInfo['status'] === 6)
        {   // 已完成
            // 更新占星师 能力分
            (new ZlcrAstr())->changeAstrScore($questionInfo['astr_id'], $qid, $tagInfo['score'], $questionInfo['question_type'], 1, 0);
        }
        //  问答评价成功    QuestionEvaluationSuccess    打点
        SensorsData::track($this->user['id'], true, 'QuestionEvaluationSuccess', [
            'question_id' => $qid,
            'remark_level' => $tagInfo['flag'],
            'remark_tag' => $tagInfo['tag_name'],
            'remark_content' => $remark,
            'add_question_nums' => (new Zlcr2UserAddQuestion())->getQuestionAddQuestionNum($qid),
        ]);
        return show(config('code.success'), '评价成功');
    }

    /**
     * 追问
     */
    public function addQuestion()
    {
        $qid = input('qid/s', '');
        $content = trim(input('content/s', ''));

        if (!$qid)
        {
            return show(config('code.error'), '请求异常，请稍后再试～');
        }

        if (!$content)
        {
            return show(config('code.error'), '请输入追问问题');
        }

        if (mb_strlen($content) > 50)
        {
            return show(config('code.error'), '追问问题最多50字');
        }

        if (Util::commentCheck($this->user['id'], ['action' => 'addQuestion', 'qid' => $qid, 'content' => $content,], 5))
        {
            return show(config('code.error'), '请求频繁，请稍后再试～');
        }

        $res = AliyunFilterWord::checkText($content, 'article_comment');
        //若内容有违规且超过配置的相似比例，则进行隐藏不显示，将标签存入库中
        if ($res)
        {
            return [
                'status' => false,
                'msg' => '内容中有敏感词',
            ];
        }

        $questionModel = new Zlcr2UserQuestion();
        $addQuestionModel = new Zlcr2UserAddQuestion();

        $questionInfo = $questionModel->getInfoById($qid, ['uid', 'status', 'gid', 'astr_id', 'question_type', 'answer_duration', 'order_num']);

        if (!$questionInfo || $questionInfo['uid'] !== $this->user['id'])
        {
            return show(config('code.error'), '服务异常，问题不存在～');
        }
        if ($questionInfo['status'] !== 5)
        {
            return show(config('code.error'), '问答状态异常，请稍后再试～');
        }
        $questionAnswerConfig = config('zlcr2_question');
        $goodsInfo = $questionAnswerConfig['info'][$questionInfo['gid']];

        $addQuestionNum = $addQuestionModel->getQuestionAddQuestionNum($qid, 1);

        try
        {
            if ($goodsInfo['free_add_num'] > $addQuestionNum)
            {   // 免费追问
                $addQuestionId = $addQuestionModel->SaveData($qid, [
                    'qid' => $qid,
                    'status' => 2,
                    'question' => $content,
                    'create_time' => $this->request->time(),
                    'pay_time' => $this->request->time(),
                ]);
                // 问题状态更新至 追问待解答
                $questionModel->UpdateData($qid, ['status' => 8]);
                // 发送短信
                $hour = (int)(date('H'));
                if ($hour >= 8 && $hour < 21)
                {   // 白天
                    $msgContent = "你的任务{$qid}有新的追问，请在3小时内给出回复，超时将受到惩罚。";
                    $tpId = 52342;
                    $timeStr = '3';
                } else
                {   // 晚上
                    $timeStr = $hour >= 21 ? '在次日11' : '在11';
                    $msgContent = "你的任务{$qid}有新的追问，请{$timeStr}点前回复，超时将受到惩罚。";
                    $tpId = 52343;
                }

                $tel = (new ZlcrAstr())->getInfoById($questionInfo['astr_id'], ['tel']);
                Util::sendHySms([$tel['tel']], '', $tpId, ['task_id' => $qid, 'time' => $timeStr]);

                // 发送占星师站内信
                (new ZlcrAstrMessage())->add($questionInfo['astr_id'], [
                    'status' => 0,
                    'is_read' => 0,
                    'astr_id' => $questionInfo['astr_id'],
                    'type' => 0, // 占星师违规消息
                    'title' => '追问提示',
                    'content' => $msgContent,
                    'target' => 'local',
                    'link' => '/quiz/answer?task_id=' . $questionModel->getTaskIdByQidAndAstrd($qid, $questionInfo['astr_id']),
                    'create_time' => $this->request->time(),
                ]);

                if ($tpId === 52342)
                {   // 白天   追问1小时是否回复检测 未回复发送消息提醒
                    Util::queuePush('question_answer_add_question_reply_notify_check', ['add_question_id' => $addQuestionId, 'astr_id' => $questionInfo['astr_id']], 3600);
                }

                // 追问回复超时 检测
                Util::queuePush('question_answer_add_question_reply_timeout_check', ['add_question_id' => $addQuestionId], Util::getToAnswerTime($this->request->time()));

                $active = (new ZhunleActivity())->getActivingGood(22, $questionInfo['gid']);
                //免费追问成功    QuestionEvaluationPaySuccess    打点
                SensorsData::track($this->user['id'], true, 'QuestionEvaluationPaySuccess', [
                    'question_id' => $qid,
                    'question_type' => $questionInfo['question_type'],
                    'is_official_active' => $active ? true : false,
                    'total_amount' => 0,
                    'order_id' => $questionInfo['order_num'],
                    'trade_type' => 0,
                    'is_success' => true,
                    'failed_reason' => '',
                    'is_voice' => $questionInfo['answer_duration'] > 0,
                ]);

                return show(config('code.success'), '追问成功', ['status' => 1]);
            } else
            {   // 付费追问
                Cache::set('question_answer:add_question:' . $qid, [
                    'content' => $content,
                ], 7200);
                return show(config('code.success'), '提交成功', ['status' => 2]);
            }
        }
        catch (\Exception $e)
        {
            Log::write('问答 UserQuestionAnswer => addQuestion()异常：' . $e->getMessage() . '失败行数：' . $e->getLine(), 'error');
            return show(config('code.error'), '服务异常，请稍后再试～');
        }
    }

    /**
     * 获取问答问题 答案信息
     */
    public function getAnswerDetail()
    {
        $qid = input('qid/s', '');

        $questionModel = new Zlcr2UserQuestion();
        $addQuestionModel = new Zlcr2UserAddQuestion();
        $questionInfo = $questionModel->getInfoById($qid, ['uid', 'status', 'gid', 'is_comment', 'astr_id', 'question_type', 'reply_time', 'answer_content', 'answer_duration', 'complain_status', 'lock_reason', 'is_anonymity']);

        if (!$questionInfo || ($this->user['id'] !== $questionInfo['uid'] && !(new Zlcr2QuestionUserView())->getQuestionUserIsView($this->user['id'], $qid)))
        {
            return show(config('code.error'), '服务异常，数据不存在');
        }

        if ($questionInfo['question_type'] === 0 || !in_array($questionInfo['status'], [5, 6, 7, 8, 20, 21], true))
        {
            return show(config('code.error'), '服务异常，请稍后再试');
        }
        if ($questionInfo['status'] === 20)
        {   // 20  退回重答相当于之前的 已解答准备追问 但是却不能追问
            $questionInfo['status'] = 5;
        }
        if ($questionInfo['status'] === 21)
        {   // 21相当于之前的 申诉成功
            $questionInfo['status'] = 7;
        }

        $isself = $this->user['id'] === $questionInfo['uid'];

        $astrInfo = (new ZlcrAstr())->getInfoById($questionInfo['astr_id'], ['nickname', 'avatar']);

        $complainText = [
            0 => '对咨询师的回复不满意？',
            1 => '你已提交申诉请耐心等待结果…',
            2 => '申诉成功，官方已介入，请保持手机畅通',
            3 => '未发现你所申诉的相关问题，',
            4 => '申诉已受理，等待咨询师补充回复',
            5 => '申诉成功，官方已介入，请保持手机畅通',
        ];
        // 问题答案信息
        $answerData = [
            'nickname' => $astrInfo['nickname'],
            'avatar' => $astrInfo['avatar'],
            'create_time' => Util::timeToStr($questionInfo['reply_time']),
            'content' => $questionInfo['answer_content'],
            'duration' => $questionInfo['answer_duration'],
            'evaluation_status' => $questionInfo['is_comment'],
            'complaint_status' => in_array($questionInfo['complain_status'], [4, 5], true) ? 2 : $questionInfo['complain_status'],
            'complaint_text' => $complainText[$questionInfo['complain_status']],
            'evaluation_is_show' => $isself && !in_array($questionInfo['complain_status'], [2, 5], true) ? 1 : 0,
        ];

        // 获取追问信息
        $addQuestionData = $addQuestionModel->getQuestionAddQuestionInfo($qid);
        $user = $isself ? $this->user : ($questionInfo['is_anonymity'] === 1 ? [
            'nickname' => '匿名用户', 'avatar' => '/test/question_answer/anonymity1.png',
        ] : (new User())->getUserinfo(['id' => $questionInfo['uid']]));
        $addQuestionList = [];
        $addQuestionStatus = [
            2 => 1,
            4 => 1,
            5 => 2,
            6 => 3,
        ];
        $questionStatus = in_array($questionInfo['status'], [5, 8], true) ? 0 : 1;    // 0=>追问中 1=>已完成

        foreach ($addQuestionData as $addQuestionDatum)
        {
            $status = $addQuestionStatus[$addQuestionDatum['status']];
            $tips = '';
            if ($status === 2)
            {
                $tips = '追问已取消，取消原因：' . $addQuestionDatum['cannel_tag_name'];
            } elseif ($status === 3)
            {
                $tips = '占星师回复超时，追问已取消';
            }
            $addQuestionAnswerData = null;
            if ($addQuestionDatum['status'] === 4)
            {
                $addQuestionAnswerData = [
                    'content' => $addQuestionDatum['answer_content'],
                    'duration' => $addQuestionDatum['answer_duration'],
                    'create_time' => Util::timeToStr($addQuestionDatum['reply_time']),
                    'nickname' => $astrInfo['nickname'],
                    'avatar' => $astrInfo['avatar'],
                ];
            }

            $addQuestionList[] = [
                'question_data' => [
                    'tag_list' => $addQuestionDatum['order_num'] ? [2] : [1, 2],
                    'content' => $addQuestionDatum['question'],
                    'create_time' => Util::timeToStr($addQuestionDatum['create_time']),
                    'tips' => $tips,
                    'nickname' => $user['nickname'],
                    'avatar' => $user['avatar'],
                    'status' => $status,
                ],
                'answer_data' => $addQuestionAnswerData,
            ];
        }
        $bottomData = null;
        if ($isself && in_array($questionInfo['status'], [5, 8], true))
        {
            // 没有发起追问 且 没有待审核的申述
            $s = $questionInfo['status'] === 5 && in_array($questionInfo['complain_status'], [0, 3], true) ? 1 : 2;
            $leftTiem = $questionInfo['reply_time'] + 172800 - $this->request->time();
            $questionAnswerConfig = config('zlcr2_question');
            $goodsInfo = $questionAnswerConfig['info'][$questionInfo['gid']];
            // 已追问次数
            $addQuestionNum = $addQuestionModel->getQuestionAddQuestionNum($qid, 1);
            if ($goodsInfo['free_add_num'] > $addQuestionNum)
            {   // 还有免费追问次数
                $gid = 0;
                $price = '0';
                $btnText = sprintf("免费追问%d次", $goodsInfo['free_add_num'] - $addQuestionNum);
            } else
            {   // 没有免费追问次数
                $gid = $questionAnswerConfig['add_question'][$questionInfo['gid']];
                $goodInfo = (new Goods())->getInfoById($gid);
                $price = (string)((float)$goodInfo['now_prize']);
                $btnText = sprintf("追问%s元/次", $price);
            }

            $statusDes = '';
            if ($questionInfo['status'] === 8)
            {
                $statusDes = '咨询师会尽快给你回复，请耐心等待~';
                $btnText = '等待回复…';
            } else
            {
                if ($questionInfo['lock_reason'])
                {
                    $statusDes = "非常抱歉，因咨询师追问回复超时，\r\n本问题不支持追问";
                    $s = 2;
                }
            }

            $bottomData = [
                'status' => $s,
                'left_time' => $leftTiem > 0 && empty($statusDes) ? $leftTiem : 0,  // 剩余的可追问时长秒数
                'gid' => $gid,    // 追问的商品ID，免费追问时，为0
                'price' => $price,  // （追问12元/次    追问的价格，若为0表示免费追问）
                'superaddition_tip' => [
                    'text1' => "1.追问的问题需要围绕你的问题和咨询师的回复进行编辑。\r\n2.如果追问的问题不符合要求，咨询师可能拒绝回答，平台不予退款。\r\n3.未收到咨询师回复将自动退款。",
                    'text2' => "8:00至21:00三小时内回复\r\n21:00至8:00十二小时内回复",
                ],  // (is_self=1时，点击提交追问的弹窗提示信息)
                'btn_text' => $btnText,   // 底部追问按钮的文案
                'status_des' => $statusDes,
            ];
        }

        $resData = [
            'answer_data' => $answerData,
            'superaddition_list' => $addQuestionList,
            'bottom_data' => $bottomData,
            'isself' => $isself ? 1 : 0,
            'is_complete' => $questionStatus,
            'question_type' => $questionInfo['question_type'], // 问题类型，打点专用字段
        ];

        return show(config('code.success'), '请求成功', $resData);
    }

    /**
     * 我的问答列表
     * @return Json
     * @throws \Exception
     */
    public function getMyQuestions()
    {
        $type = input('type/d', 1);  // 1=>我的问题, 2=> 我讨论的, 3=> 我蹭看的
        $questionModel = new Zlcr2UserQuestion();
        switch ($type)
        {
            case 2:
                $commentModel = new ArticleComment();
                $cids = $commentModel->getUserCommentIds($this->user['id']);
                if ($cids['data'])
                {
                    $res = [];
                    foreach ($cids['data'] as $qid => $id)
                    {
                        $question = $questionModel->getInfoById((int)$qid);
                        if ($question)
                        {
                            $question['is_read'] = 1;
                            $question['id'] = (int)$id;
                            $question['qid'] = (string)$qid;
                            $res[$qid] = $question;
                        }
                    }
                    $cids['data'] = $res;
                    $resData = $questionModel->getMyQuestionList($this->user['id'], $cids, $type);
                }
                break;
            case 3:
                $viewModel = new Zlcr2QuestionUserView();
                $view = $viewModel->getListPage($this->user['id']);
                if ($view['data'])
                {
                    $question = $questionModel->batchGetInfoByIds(array_column($view['data'], 'qid'));
                    $res = [];
                    foreach ($view['data'] as $value)
                    {
                        $question[$value['qid']]['is_read'] = $value['new_answer'] ? 0 : 1;
                        $question[$value['qid']]['id'] = $value['id'];
                        $question[$value['qid']]['qid'] = $value['qid'];
                        $res[$value['id']] = $question[$value['qid']];
                    }
                    $view['data'] = $res;
                    $resData = $questionModel->getMyQuestionList($this->user['id'], $view, $type);
                }
                break;
            default:    // 1我的问题
                $pageData = $questionModel->getListPage($this->user['id'], 'id', [], 0, 'desc', 0);
                $resData = $questionModel->getMyQuestionList($this->user['id'], $pageData, $type);
        }

        return show(config('code.success'), '请求成功', $resData ?? []);
    }

    /**
     * 我的问答记录删除
     */
    public function delMyQuestions()
    {
        $type = input('type/d', 1);  // 1=>我的问题, 2=> 我讨论的, 3=> 我蹭看的
        $id = input('id/d', 1);  // 1=>我的问题, 2=> 我讨论的, 3=> 我蹭看的
        if (Util::IsIos() && Util::checkAppVersion('2.13.0') === '小')
        {
            if ($id < 10000000)
            {
                $type = 3;
            } else
            {
                $type = 1;
            }
        }
        switch ($type)
        {
            case 2:
                $comment = current((new ArticleComment())->batchGetInfo([$id], ['uid']));
                if (!$comment || $comment['uid'] != $this->user['id'])
                {
                    return show(config('code.error'), '删除失败');
                }
                (new ArticleComment())->commentDel($this->user['id'], $id);
                break;
            case 3:
                $view = (new Zlcr2QuestionUserView())->getInfoById($id, ['uid']);
                if (!$view || $view['uid'] != $this->user['id'])
                {
                    return show(config('code.error'), '删除失败');
                }
                (new Zlcr2QuestionUserView())->UpdateData($this->user['id'], $id, ['is_hide' => 1]);
                break;
            default:    // 1我的问题
                $question = (new Zlcr2UserQuestion())->getInfoById($id, ['uid', 'is_top', 'is_recommend_top']);
                if (!$question || $question['uid'] != $this->user['id'])
                {
                    return show(config('code.error'), '删除失败');
                }
                (new Zlcr2UserQuestion())->UpdateData($id, ['delete_time' => time(), 'uid' => $this->user['id']]);
                if ($question['is_top'] === 1)
                {
                    CacheManage::getInstance()->setCacheConfig('question_answer.question')->rmCache('admin_recommended_top');
                }
                if ($question['is_recommend_top'] === 1)
                {
                    CacheManage::getInstance()->setCacheConfig('question_answer.question')->delJudge($id, 'admin_recommended');
                }
        }

        return show(config('code.success'), '删除成功');
    }

    /**
     *  问答蹭看已读
     * @return Json
     * @throws \Exception
     */
    public function readView()
    {
        $id = input('id/d', 1);
        $view = (new Zlcr2QuestionUserView())->getInfoById($id, ['uid']);
        if (!$view || $view['uid'] != $this->user['id'])
        {
            return show(config('code.error'), '操作失败');
        }
        (new Zlcr2QuestionUserView())->UpdateData($this->user['id'], $id, ['new_answer' => 0]);
        return show(config('code.success'), '操作成功');
    }

    /**
     * 问题-评论
     */
    public function questionComment()
    {
        $qid = input('qid/s', 0);
        $content = trim(htmlspecialchars(input('content/s', '')));

        if ($content === '')
        {
            return show(config('code.error'), '讨论内容不能为空');
        }
        if (!$qid)
        {
            return show(config('code.error'), '请求异常');
        }
        if ($this->user['no_comment'])
        {
            return show(config('code.error'), '发布讨论失败，已被禁止发布讨论');
        }
        $questionModel = new Zlcr2UserQuestion();
        $questionInfo = $questionModel->getInfoById($qid, ['uid', 'read_num', 'comment_num', 'same_num', 'id', 'consult_time', 'status', 'question_type', 'is_anonymity', 'is_hide']);

        if (!$questionInfo)
        {
            return show(config('code.error'), '问题不存在');
        }
        $data = [
            'aid' => $qid,
            'uid' => (int)$this->user['id'],
            'content' => $content,
            'type' => 4,    //类型 1=>星文评论，2=>女神动态评论，3=>女神专区评论 4=>问答 必传
            'status' => 0,   // 状态 0 正常 -1 删除
        ];
        $res = (new ArticleComment())->commentAdd($this->user, $data, false);

        if ($res['status'])
        {
            //发布讨论    QuestionCommentSuccess    打点
            SensorsData::track($this->user['id'], true, 'QuestionCommentSuccess', [
                'question_id' => $qid,
                'question_type' => $questionInfo['question_type'],
                'author_id' => $questionInfo['uid'],
                'comment_content' => $content,
            ]);

            $anonymityNickname = '匿名用户';
            $anonymityAvatar = '/test/question_answer/anonymity1.png';

            $rData = [
                'id' => (int)$res['id'],
                'avatar' => $questionInfo['uid'] === $this->user['id'] && $questionInfo['is_anonymity'] === 1 ? $anonymityAvatar : $this->user['avatar'],
                'nickname' => $questionInfo['uid'] === $this->user['id'] && $questionInfo['is_anonymity'] === 1 ? $anonymityNickname : $this->user['nickname'],
                'create_time' => '刚刚',
                'content' => htmlspecialchars_decode($content),
                'reply_num' => 0,
                'good_num' => 0,
                'is_good' => 0,
                'is_owner' => 1,
                'user_tag' => $questionInfo['uid'] === $this->user['id'] ? 1 : 0,    // 用户标签 0=>没有 1=>提问者 2=>楼主
                'reply_list' => [],
                'vip' => (new ZlUserVip())->getUserVipLevel($this->user['id']),
            ];

            $questionModel->changeQuestionInfo($questionInfo, 2, 1);

            if ($questionInfo['uid'] === $this->user['id'])
            {
                (new ArticleComment())->delQuestionAnswerRecommentIdCache($qid, 4);
            }

            return show(config('code.success'), '评论成功', $rData);
        }
        return show(config('code.error'), $res['msg']);

    }

    /**
     * 评论回复
     */
    public function commentReply()
    {
        $commentId = input('cid/d', 0);
        $pid = input('pid/d', 0);
        $content = trim(htmlspecialchars(input('param.content/s', '')));
        $commentModel = new ArticleComment();

        if ($content === 0)
        {
            return show(config('code.error'), '评论内容不能为空');
        }
        if (!$commentId)
        {
            return show(config('code.error'), '讨论不存在');
        }
        if ($this->user['no_comment'])
        {
            return show(config('code.error'), '评论失败，已被禁止评论');
        }

        // 评论详情
        $commentInfo = current($commentModel->batchGetInfo([$commentId], ['uid', 'aid', 'goods', 'reply']));
        if (!$commentInfo)
        {
            return show(config('code.error'), '数据不存在');
        }
        // 判断 用户是否允许回复他
        if ($pid)
        {   // 回复->评论回复
            // 获取回复的 评论回复用户uid
            $replyUid = (new ArticleCommentReply())->getInfoById($pid, ['uid1']);
            if ($replyUid['uid1'] != $this->user['id'])
            {   // 不是回复自己
                $replyStatus = (new UserPush())->getUserReplyStatus((int)$replyUid['uid1']); // 是否允许回复自己 true 允许 false 不允许
                if (!$replyStatus)
                {   // 不允许回复
                    return show(config('code.error'), '对方关闭了评论回复');
                }
            }
        } else
        {   // 回复讨论
            // if ($commentInfo['uid'] != $this->user['id'])
            // {   // 不是自己评论自己事
            //     $replyStatus = (new UserPush())->getUserReplyStatus((int)$commentInfo['uid']); // 是否允许回复自己 true 允许 false 不允许
            //     if (!$replyStatus)
            //     {   // 不允许回复
            //         return show(config('code.error'), '对方关闭了评论回复');
            //     }
            // }
        }

        $data = [
            'comment_id' => $commentId,
            'pid' => $pid,
            'content' => $content,
            'uid' => (int)$this->user['id'],
            'status' => 0,   // 状态 0 正常 -1 删除
        ];

        $res = (new ArticleCommentReply())->addCommentReply($this->user, $data, false);

        if ($res['status'])
        {
            $question = (new Zlcr2UserQuestion())->getInfoById($commentInfo['aid'], ['uid']);
            //  发布回复成功    QuestionReplySuccess    打点
            SensorsData::track($this->user['id'], true, 'QuestionReplySuccess', [
                'question_id' => $commentInfo['aid'],    // 是否匿名
                'author_id' => $question['uid'],// 提问者
                'owner_id' => $commentInfo['uid'],//楼主
                'reply_content' => $content,
            ]);

            $questionModel = new Zlcr2UserQuestion();
            $questionInfo = $questionModel->getInfoById($commentInfo['aid'], ['uid', 'is_anonymity']);
            if ($questionInfo['uid'] === $this->user['id'])
            {
                $userTag = 1;
            } elseif ((int)$commentInfo['uid'] === $this->user['id'])
            {
                $userTag = 2;
            }

            $anonymityNickname = '匿名用户';
            $anonymityAvatar = '/test/question_answer/anonymity1.png';

            $commentModel->setCommentAndGoodSum($commentInfo['aid'], $commentId, $commentInfo['goods'] + $commentInfo['reply'] + 1);

            $rData = [
                'id' => (int)$res['id'],
                'avatar1' => $questionInfo['uid'] === $this->user['id'] && $questionInfo['is_anonymity'] === 1 ? $anonymityAvatar : $this->user['avatar'],
                'nickname1' => $questionInfo['uid'] === $this->user['id'] && $questionInfo['is_anonymity'] === 1 ? $anonymityNickname : $this->user['nickname'],
                'nickname2' => $pid ? $res['nickname2'] : null,
                'create_time' => '刚刚',
                'content' => htmlspecialchars_decode($content),
                'content_type' => 1,
                'good_num' => 0,
                'is_good' => 0,
                'is_owner' => 1,
                'user_tag' => $userTag ?? 0,    // 用户标签 0=>没有 1=>提问者 2=>楼主
                'vip' => (new ZlUserVip())->getUserVipLevel($this->user['id']),
            ];

            return show(config('code.success'), '评论成功', $rData);
        }
        return show(config('code.error'), $res['msg']);
    }

    /**
     * 获取用户问题评价
     */
    public function getUserQuestionComment()
    {
        $qid = input('qid/s', '');
        $comment = (new Zlcr2UserQuestionComment())->getInfoById($qid);
        if ($comment)
        {
            $res = [];
            $res['level'] = $comment['level'];
            $res['comment'] = $comment['comment'];
            //获取占星师信息
            $astr = (new ZlcrAstr())->getInfoById($comment['astr_id'], ['nickname', 'avatar']);
            $res['name'] = $astr['nickname'];
            $res['avatar'] = $astr['avatar'];
            //获取标签信息
            $tagModel = new ZlcrTag();
            $tag = $tagModel->getLevelTag(4, $comment['level']);
            $tmp = [];
            foreach ($tag as $k => $t)
            {
                if ($t['id'] == $comment['tid'])
                {
                    $t['is_select'] = 1;
                } else
                {
                    $t['is_select'] = 0;
                }
                $tmp[] = $t;
            }
            $res['tags'] = $tmp;
            return show(config('code.success'), '获取成功过', $res);
        }
        return show(config('code.error'), '内容不存在');
    }
}
